package com.revelvy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * Author: Revelvy
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket(Environment environment) {
        // 分环境启用Swagger2
        Profiles profiles = Profiles.of("dev","test");
        boolean flag = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                // 是否启用Swagger2
                .enable(flag)
                .apiInfo(apiInfo())
                // 接口扫描路径
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.revelvy.controller"))
                .build();
    }

    // 配置Swagger信息：apiInfo
    private ApiInfo apiInfo() {
        return new ApiInfo(
                "Revelvy的API文档",
                "UniconBackend API文档",
                "v1.0",
                "https://www.revelvy.cn",
                new Contact(
                        "Revelvy",
                        "https://www.revelvy.cn",
                        "revelvy@qq.com"),
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>());
    }
}
